home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 14 / 014.d81 / sort collection (.txt) < prev    next >
Commodore BASIC  |  2022-08-26  |  2KB  |  92 lines

  1. 0 ifx=0thenx=1:                           load"shell-metzner.o",8,1
  2. 1 nn=100:dima$(nn+1)
  3. 3 :
  4. 5 gosub10000
  5. 10 goto20000
  6. 15 :
  7. 19 rem     shell
  8. 20 gosub500  : rem __ set array
  9. 25 gosub1000 : rem __ set time = 00
  10. 30 g=int(nn/2)
  11. 40 n=0:fori=1tonn-g
  12. 50 ifa$(i)>a$(i+g)thent$=a$(i):a$(i)=a$(i+g):a$(i+g)=t$:n=1:poke53280,rnd(1)*15
  13. 60 nexti:ifn=1then40
  14. 70 g=int(g/2):ifg>=1then40
  15. 80 gosub2000 : rem __ print time
  16. 87 return
  17. 88 :
  18. 90 rem  modified insertion
  19. 92 gosub500  : rem  __ set array
  20. 95 gosub1000 : rem  __ set time= 00
  21. 100 forx=0tonn-1
  22. 110 fory=x+1tonn
  23. 120 ifa$(x)>a$(y)thent$=a$(x):a$(x)=a$(y):a$(y)=t$:poke53280,rnd(1)*15
  24. 130 nexty:nextx
  25. 140 gosub2000 : rem __ print time
  26. 150 return
  27. 155 :
  28. 200 rem shell/metzner sort
  29. 204 gosub 500  : rem __ set array
  30. 205 gosub 1000 : rem __ set time = 00
  31. 210 s=nn
  32. 220 z=0
  33. 230 s=int((s+1)/2)
  34. 240 fori=1tonn-s
  35. 250 ifa$(i)<=a$(i+s)then300
  36. 260 t$=a$(i)
  37. 270 a$(i)=a$(i+s)
  38. 280 a$(i+s)=t$
  39. 290 z=1:poke53280,rnd(1)*15
  40. 300 nexti
  41. 320 if(z=1)or(s>1)then220
  42. 330 gosub2000 : rem  __ print time
  43. 340 return
  44. 350 :
  45. 360 :
  46. 400 rem   m/l  shell metzner
  47. 410 gosub500     : rem  __ set array
  48. 420 gosub1000    : rem  __ set time=00
  49. 430 sys49152a$(0): rem  ___ sort
  50. 440 gosub2000    : rem  __ print time
  51. 450 return
  52. 460 :
  53. 470 :
  54. 500 print"[147]before :":print:forx=0tonn+1:a$(x)=chr$(65+rnd(1)*26):printa$(x);:
  55. 505 next:print:print:return
  56. 510 :
  57. 1000 print"sorting...":ti$="000000"
  58. 1010 return
  59. 1020 :
  60. 2000 print"after :":print:forx=1tonn:printa$(x);:next:print:print
  61. 2001 t=int(ti/60)
  62. 2005 print"it took"t"seconds";:ift<2thenprint"[157] [157]";:
  63. 2006 print" to sort"nn"elements."
  64. 2010 print"      <press a key to continue>"
  65. 2020 poke198,0:wait198,1:poke198,0
  66. 2030 return
  67. 10000 print"[147]"spc(11)"sort comparison":poke53281,0:poke53280,5
  68. 10002 printspc(17)"by"
  69. 10004 printspc(12)"alan gardner"
  70. 10006 print"loadstar is not public domain, but feel"
  71. 10008 print"feel free to use any of the sort "
  72. 10010 print"routines found in this program in your"
  73. 10012 print"own programs."
  74. 10020 print"         press a key to continue"
  75. 10030 poke198,0:wait198,1:poke198,0
  76. 10040 return
  77. 20000 rem    menu/selection
  78. 20010 print"[147]            *** menu ***"
  79. 20020 print"    1.  modified insertion"
  80. 20030 print"    2.  shell sort"
  81. 20040 print"    3.  shell-metzner sort"
  82. 20050 print"    4.  machine-language shell-metzner"
  83. 20052 print"    5.  exit program"
  84. 20060 print"which ?";
  85. 20070 poke198,0:wait198,1:getz$:              z=val(z$)
  86. 20080 ifz$=""orval(z$)=0orz<0orz>5            then20070
  87. 20090 onzgosub90,19,200,400,63000
  88. 20100 goto20000
  89. 63000 rem   connect back to l.s.
  90. 63010 print"[147]load"chr$(34)"payload"chr$(34)",8":print"run"
  91. 63020 poke631,13:poke632,13:poke198,2:        end
  92.